package com.jys.crazyIm;

import com.jys.im.common.bean.Notification;
import com.jys.imServer.distributed.PeerManager;
import com.jys.imServer.server.session.RemoteSession;
import com.jys.util.JsonUtil;
import com.google.gson.reflect.TypeToken;
import org.junit.Test;

public class NotificationJsonConvert {

    @Test
    public  void convertFromJson()
    {
        RemoteSession remoteSession = RemoteSession.builder()
                .sessionId("ddd")
                .imNode(PeerManager.getInst().getLocalNode())
                .userId("ddd")
                .valid(true)
                .build();
        Notification<RemoteSession> notification = new Notification<RemoteSession>(remoteSession);
        notification.setType(Notification.SESSION_OFF);
        String json = JsonUtil.pojoToJson(notification);



        Notification<RemoteSession> no2 = JsonUtil.jsonToPojo(json,new TypeToken<Notification<RemoteSession>>() {}.getType());

        RemoteSession r2=no2.getData();
        System.out.println("no2 = " + no2);


    }

}
